﻿using System;
using System.Collections.ObjectModel;
using BusinessLogic.Models.LogicModels.Security;
using Framework.Dependency;
using Framework.Validation;
using Interfaces.Enums;
using Interfaces.Models;
using Interfaces.Validation;
using Interfaces.Validation.Services;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace FrameworkUnitTests
{
    [TestClass]
    public class ValidationTests
    {
        [TestMethod]
        public void ValidateUser()
        {

            var mockValidServ = new Mock<IUserValidationService>();
            mockValidServ.Setup(x => x.IsEmailExists(It.IsAny<string>())).Returns(false);
            mockValidServ.Setup(x => x.IsUserNameExists(It.IsAny<string>())).Returns(false);


            DependencyManager.Container.RegisterInstance(mockValidServ.Object);
            
            var modelToValidate = new User
                {
                    Email = "myemail@mail.ru",
                    UserName = "myusername",
                    Id = Guid.NewGuid(),
                    Password = "123456",
                    Roles = new Collection<IRole>()
                };
            
            modelToValidate.Roles.Add(new Role
            {
                Id = Guid.NewGuid(),
                Type = RoleType.User,
                Users = new Collection<IUser> { modelToValidate }
            });

            var validator = new GenericValidator();

            var result = validator.Validate(modelToValidate, RulesetNames.Create);

            Assert.IsTrue(result.IsValid);
        }
    }
}
